<template>
	<view class="page">
		<wmAddress 
			:list="list" 
			@add='add'
			@setDefault="handleSetDefault" 
			@choose="handleChoose" 
			@submit="handleSubmit" 
			@delete="handleDelete">
		</wmAddress>
	</view>
</template>

<script>
	import wmAddress from "@/components/address/components/address/address.vue"
    import {
		getAddressList
	} from "@/api/addrss"
	export default {
		data() {
			return {
				page:1,
				list: [  ],
				type:''
			}
		},
		components: {
			wmAddress
		},
		onLoad(e) {
			this.type =e.type
		},
        onShow() {
			this.getAddressList()
		},
		methods: {
            getAddressList(){
                getAddressList({page:this.page,limit:40}).then(res=>{
                    this.list = res.data
                })
            },
			// 选择地址
			handleChoose(data) {
				if(this.type ){}
				else{
					uni.setStorageSync('addressInfo' ,JSON.stringify(data))
					// uni.$emit('addressChoosed', data)
					uni.navigateBack()
				}
				
			},
			// 设置默认地址
			handleSetDefault(data) {
				console.log(data)
			},
			// 添加或编辑地址（data中有id即为编辑，否则为添加）
			handleSubmit(data) {
				console.log(data);
			},
			// 删除地址
			handleDelete(data) {
				console.log(data);
			},
			add(data){
				let id = data&&data.id ? data.id :''
				uni.navigateTo({
					url:'/pageA/address/add?id='+id
				})
			}
		}
	}
</script>

<style>
	
</style>
